package com.zwk.nginxmanage.config;

import com.zwk.nginxmanage.entity.NginxResource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@ConfigurationProperties(prefix = "resources")
@Component
@Data
public class ResourceConfig {
    private String pathPrefix;
    private String urlPrefix;
    private List<NginxResource> resourceList;

    @PostConstruct
    public void init(){
        List<NginxResource> resourceList = this.resourceList;
        resourceList.forEach(res->{
            res.setType("dir");
            res.setUrl(urlPrefix+res.getSimplePath());
            res.setPath(pathPrefix+res.getSimplePath());
        });
    }
}
